using Microsoft.WowAddonStudio.FrameXml.Serialization.LayoutFrames;
using Microsoft.WowAddonStudio.FrameXml.Serialization.Support;
using NUnit.Framework;

namespace Microsoft.WowAddonStudio.FrameXml.Serialization.Tests
{
    [TestFixture]
    public class FrameXmlLoaderTest
    {
        private const string schemaPath = "Data/UI.xsd";

        [Test]
        public void LoadUiTest()
        {
            // Create validating FrameXML loader
            var frameXmlLoader = new FrameXmlLoader { SchemaPath = schemaPath };

            // Load Outfitter Ui
            var ui = frameXmlLoader.LoadUi("Data/Acceptance/Outfitter.xml");

            Assert.IsNotNull(ui);
        }

        [Test]
        public void ParentTest()
        {
            // Create validating FrameXML loader
            var frameXmlLoader = new FrameXmlLoader { SchemaPath = schemaPath };

            // Load XML for Frame ExpandedName test and validate parents
            var ui = frameXmlLoader.LoadUi("Data/Simple/FrameExpandedName.xml");

            Assert.IsNotNull(ui);

            // Assert the parents of both layered and frame children
            Assert.AreEqual(1, ui.LayoutFrames.Count);

            // Top-level Frame does not have a parent (Ui is not a valid parent)
            Assert.IsNull(ui.LayoutFrames[0].ParentFrame);

            // Layerable layout frame and child frame should both have correct parent
            Assert.AreSame(ui.LayoutFrames[0], ((Frame)ui.LayoutFrames[0]).Layers[0].Items[0].ParentFrame);
            Assert.AreSame(ui.LayoutFrames[0], ((Frame)ui.LayoutFrames[0]).Frames[0].ParentFrame);
        }
    }
}
